package com.fivefu.core.hik.controller;

import com.alibaba.fastjson.JSON;
import com.fivefu.base.common.utils.str.StrUtils;
import com.fivefu.base.web.controller.BaseController;
import com.fivefu.base.web.vo.ResultInfo;
import com.fivefu.core.hik.services.DeviceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 * 海康设备表 前端控制器
 * </p>
 *
 * @author 
 * @since 2022-06-30 14:17:37
 */
@Api(tags = "视频资源")
@RestController
@RequestMapping("/hikdevice")
public class DbHikDeviceController extends BaseController {

    private static final Logger logger = LoggerFactory.getLogger(DbHikDeviceController.class);

    @Autowired
    private DeviceService deviceService;

    @ApiOperation(value = "查询编码设备列表v2",httpMethod = "POST",response = ResultInfo.class,notes = "查询编码设备列表v2")
    @RequestMapping(path = "/searchEncodeDevice",method = RequestMethod.POST)
    public ResultInfo searchEncodeDevice () {
        try {
            deviceService.searchEncodeDevice();
            return ResultInfo.renderSuccess("查询编码设备列表v2成功");
        } catch (Exception e) {
            logger.error("编码设备列表出现异常" + e.getMessage(),e);
            return ResultInfo.renderError("查询编码设备列表v2失败");
        }
    }

    @ApiOperation(value = "根据区域获取下级编码设备列表",httpMethod = "POST",response = ResultInfo.class,notes = "根据区域获取下级编码设备列表")
    @RequestMapping(path = "/subResourcesEncodeDevice",method = RequestMethod.POST)
    public ResultInfo subResourcesEncodeDevice () {
        try {
            deviceService.subResourcesEncodeDevice();
            return ResultInfo.renderSuccess("获取区域下级编码设备列表成功");
        } catch (Exception e) {
            logger.error("根据区域获取下级编码设备列表出现异常" + e.getMessage(),e);
            return ResultInfo.renderError("获取区域下级编码设备列表失败");
        }
    }

    @ApiOperation(value = "增量获取编码设备数据",httpMethod = "POST",response = ResultInfo.class,notes = "增量获取编码设备数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sTime",value = "针对更新时间的查询开始日期，IOS8601格式(48小时以内)",paramType = "query", required = true, dataType = "String")
    })
    @RequestMapping(path = "/timeRangeEncodeDevice",method = RequestMethod.POST)
    public ResultInfo timeRangeEncodeDevice (@RequestParam String sTime) {
        logger.info("增量获取编码设备数据请求参数为：" + JSON.toJSONString(request.getParameterMap()));
        try {
            if (StrUtils.isNull(sTime)) {
                return ResultInfo.renderError("查询开始时间不能为空");
            }
            deviceService.timeRangeEncodeDevice(sTime);
            return ResultInfo.renderSuccess("增量获取编码设备数据成功");
        } catch (Exception e) {
            logger.error("增量获取编码设备数据出现异常：" + e.getMessage(),e);
            return ResultInfo.renderError("增量获取编码设备数据失败");
        }
    }





}
